/**
 * Created by Eric.Dou on 4/14/14.
 */
define(function (require) {
    var comm = require('lib/commons');
    return function (helper, $) {
        helper.register('craeteWidgets', function (options) {
            this.condition = function (opt) {
                return comm.hasPro(opt, 'target');
            };
            var target = options.target;
            if (comm.hasPro(options, 'widgets')) {
                try {
                    var widgetName = options.widgets;
                    if (comm.hasPro(options, 'options')) {
                        $(target)[widgetName](options.options);
                    }
                    else {
                        $(target)[widgetName]();
                    }
                    return true;
                } catch (error) {
                    return false;
                }
            } else {
                if (comm.hasPro(options, 'options')) {
                    //if exist the options property means those options property be depended by other method or some
                    // process.
                    $(target).data("cache-options", options.options);
                }
            }
        });
    }
});
